clear all

// SET MACROS
global Input  "Y:/limited/Michigan_CTE/funding_change/data_final"
global Output "Y:/limited/Michigan_CTE/funding_change/output/figures"

qui include "Y:/limited/Michigan_CTE/funding_change/code/analyze/figures/00_colors.do"

local demographics "female black hisp another_race sped lep econdis"
local academics "test_avg_g8 test_avg_sq_g8 test_avg_g8_imp attendance_g8 attendance_g8_imp"

// LOAD DATA
use $Input/compiled_student_analysis_data.dta


keep if grad_year >= 2012
replace c2014 = 0

// RUN REGRESSIONS
gen cohort = .
gen part_over_time     = .
gen part_over_time_l95 = .
gen part_over_time_u95 = .
gen conc_over_time     = .
gen conc_over_time_l95 = .
gen conc_over_time_u95 = .
gen comp_over_time     = .
gen comp_over_time_l95 = .
gen comp_over_time_u95 = .

eststo: reghdfe cte_any c2012-c2019 `demographics' `academics', a(school) vce(cluster school)

local i = 1
forvalues x = 2012/2019 {
  replace part_over_time = 100 * _b[c`x'] in `i'
  replace part_over_time_l95 = 100 * _b[c`x'] - (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  replace part_over_time_u95 = 100 * _b[c`x'] + (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  replace cohort = `x' in `i'
  local ++i
}

eststo: reghdfe cte_conc_comp c2012-c2019 `demographics' `academics', a(school) vce(cluster school)

local i = 1
forvalues x = 2012/2019 {
  replace conc_over_time = 100 * _b[c`x'] in `i'
  replace conc_over_time_l95 = 100 * _b[c`x'] - (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  replace conc_over_time_u95 = 100 * _b[c`x'] + (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  local ++i
}

eststo: reghdfe cte_comp c2012-c2019 `demographics' `academics', a(school) vce(cluster school)

local i = 1
forvalues x = 2012/2019 {
  replace comp_over_time = 100 * _b[c`x'] in `i'
  replace comp_over_time_l95 = 100 * _b[c`x'] - (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  replace comp_over_time_u95 = 100 * _b[c`x'] + (invttail(e(df_r),0.025) * 100 * _se[c`x']) in `i'
  local ++i
}

keep cohort part_over_time part_over_time_l95 part_over_time_u95 ///
  conc_over_time conc_over_time_l95 conc_over_time_u95 ///
  comp_over_time comp_over_time_l95 comp_over_time_u95
drop if missing(cohort)

// DRAW GRAPH
tw (rarea part_over_time_l95 part_over_time_u95 cohort, color("$c3%30") lwidth(none)) ///
   (rarea conc_over_time_l95 conc_over_time_u95 cohort, color("$c2%30") lwidth(none)) ///
   (rarea comp_over_time_l95 comp_over_time_u95 cohort, color("$c1%30") lwidth(none)) ///
   (connected part_over_time conc_over_time comp_over_time cohort, sort ///
   scale(1.1) ///
   mc("$c3" "$c2" "$c1") ///
   m(D T O) ///
   lc("$c3" "$c2" "$c1") ///
   lp(shortdash dash solid)), ///
   xline(2014.5 2015.5, lc(gs12) lp(-)) ///
   yline(0, lc(gs11)) ///
   text(13.6 2014.5 "Funding" "increased," "new formula" "announced", placement(0) color(black) box bcolor(white) margin(b=1)) ///
   text(14.4 2015.5 "New" "formula" "applied", placement(0) color(black) box bcolor(white) margin(t=2 b=1)) ///
   xlabel(2012/2019) ///
   xtitle(" " "Cohort Graduation Year", margin(t=2)) ///
   ylabel(-5(5)15, angle(0) glc(gs13) glw(vthin) glp(shortdash) gmax) ///
   ytitle("Percentage Point Change" " ") ///
   legend(order(6 5 4) label(4 "Participants") label(5 "Concentrators") label(6 "Completers") rows(1) symxsize(7) region(lstyle(none))) ///
   graphregion(color(white)) bgcolor(white) ///
   xsize(7.5) ysize(3.25) ///
	 scheme(s2color)

// EXPORT GRAPH


graph save $Output/02a_reg_student_advancement.gph, replace
*graph export $Output/02_reg_student_advancement.pdf, replace





di 9.876807/29.5228
di 12.88219/.1515877